/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.mycompany.psc.entities;

import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author A7med
 */
@Entity
@Table(name = "tender_items_data")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "TenderItemsData.findAll", query = "SELECT t FROM TenderItemsData t"),
    @NamedQuery(name = "TenderItemsData.findById", query = "SELECT t FROM TenderItemsData t WHERE t.id = :id"),
    @NamedQuery(name = "TenderItemsData.findByTitle", query = "SELECT t FROM TenderItemsData t WHERE t.title = :title"),
    @NamedQuery(name = "TenderItemsData.findByTitleAndProject", query = "SELECT t FROM TenderItemsData t WHERE t.title = :title and t.parent.project=:project"),
    @NamedQuery(name = "TenderItemsData.findByRate", query = "SELECT t FROM TenderItemsData t WHERE t.rate = :rate"),
    @NamedQuery(name = "TenderItemsData.findByPrice", query = "SELECT t FROM TenderItemsData t WHERE t.price = :price"),
    @NamedQuery(name = "TenderItemsData.findByLossRate", query = "SELECT t FROM TenderItemsData t WHERE t.lossRate = :lossRate"),
    @NamedQuery(name = "TenderItemsData.findByQuantity", query = "SELECT t FROM TenderItemsData t WHERE t.quantity = :quantity")})
public class TenderItemsData implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id")
    private Integer id;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 255)
    @Column(name = "title")
    private String title;
    @Basic(optional = false)
    @NotNull
    @Column(name = "rate")
    private float rate;
    @Basic(optional = false)
    @NotNull
    @Column(name = "price")
    private float price;
    @Basic(optional = false)
    @NotNull
    @Column(name = "loss_rate")
    private float lossRate;
    @Basic(optional = false)
    @NotNull
    @Column(name = "quantity")
    private int quantity;
    @Basic(optional = false)
    @NotNull
    @Lob
    @Size(min = 1, max = 65535)
    @Column(name = "notes")
    private String notes;
    @JoinColumn(name = "parent", referencedColumnName = "item_id")
    @ManyToOne(optional = false)
    private TenderItems parent;

    public TenderItemsData() {
    }

    public TenderItemsData(Integer id) {
        this.id = id;
    }

    public TenderItemsData(Integer id, String title, float rate, float price, float lossRate, int quantity, String notes) {
        this.id = id;
        this.title = title;
        this.rate = rate;
        this.price = price;
        this.lossRate = lossRate;
        this.quantity = quantity;
        this.notes = notes;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public float getRate() {
        return rate;
    }

    public void setRate(float rate) {
        this.rate = rate;
    }

    public float getPrice() {
        return price;
    }

    public void setPrice(float price) {
        this.price = price;
    }

    public float getLossRate() {
        return lossRate;
    }

    public void setLossRate(float lossRate) {
        this.lossRate = lossRate;
    }

    public int getQuantity() {
        return quantity;
    }

    public void setQuantity(int quantity) {
        this.quantity = quantity;
    }

    public String getNotes() {
        return notes;
    }

    public void setNotes(String notes) {
        this.notes = notes;
    }

    public TenderItems getParent() {
        return parent;
    }

    public void setParent(TenderItems parent) {
        this.parent = parent;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof TenderItemsData)) {
            return false;
        }
        TenderItemsData other = (TenderItemsData) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.mycompany.psc.entities.TenderItemsData[ id=" + id + " ]";
    }
    public double getUnitTotal(){
            return price*(1+(lossRate/100))*quantity;
    }
     public TenderItemsData crateCopy(){
         TenderItemsData copy=new TenderItemsData();
        copy.setLossRate(lossRate);
        copy.setNotes(notes);
        copy.setPrice(price);
        copy.setQuantity(quantity);
        copy.setRate(rate);
        copy.setTitle(title);
        return copy;
        
    }
}
